//
//  NormalDZNEmptyDataSouce.m
//  QingFengApp
//
//  Created by 徐欣武 on 16/1/11.
//  Copyright © 2016年 QingFeng. All rights reserved.
//

#import "NormalDZNEmptyDataSouce.h"
#import "NotificationMacro.h"

@interface NormalDZNEmptyDataSouce ()

@property(nonatomic, weak) UIScrollView *scrollView;

@end

@implementation NormalDZNEmptyDataSouce

- (instancetype)initWithScrollView:(UIScrollView *)scrollView {

    self = [super init];
    if (self) {

        self.scrollView = scrollView;
        self.scrollView.emptyDataSetSource = self;
        self.scrollView.emptyDataSetDelegate = self;
    }
    return self;

}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {

    UIImage *logoImage;
    switch (self.dznEmptyStatus) {
        case DZNEmptyStatusNormal:
            logoImage = [UIImage imageNamed:@"暂无数据-(1)"];// self.logoImg;
            break;
        case DZNEmptyStatusFailure: {
            logoImage = [UIImage imageNamed:@"加载失败"];
            break;
        }
        case DZNEmptyStatusNotOnLine: {
            logoImage = [UIImage imageNamed:@"暂无网络"];
            break;
        }
    }

    return logoImage;

}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {

//    return -75;
    return self.verticalOff;
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {

    NSString *title;
    switch (self.dznEmptyStatus) {
        case DZNEmptyStatusNormal:
            title = NSLocalizedString(@"暂无数据", nil);// self.title;
            break;
        case DZNEmptyStatusFailure: {
            title = NSLocalizedString(@"加载失败", nil) ;
            break;
        }
        case DZNEmptyStatusNotOnLine: {
            title = NSLocalizedString(@"网络异常", nil);
            break;
        }
    }

    if (!title)
        return nil;

    NSDictionary *attributes = @{NSFontAttributeName :kGeneralFontSize,
                                 NSForegroundColorAttributeName : [UIColor colorWithHex:@"3c3c3c"]};
    return [[NSAttributedString alloc] initWithString:title attributes:attributes];
}

- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {

    NSString *des;
    switch (self.dznEmptyStatus) {
        case DZNEmptyStatusNormal:
            des = self.des;
            break;
        case DZNEmptyStatusFailure: {
            des = @"点击刷新";
            break;
        }
        case DZNEmptyStatusNotOnLine: {
            des = @"请检查你的手机是否联网";
            break;
        }
    }

    if (!des)
        return nil;

    NSDictionary *attributes = @{NSFontAttributeName :kGeneralFontSize,            NSForegroundColorAttributeName : [UIColor colorWithHex:@"3c3c3c"]};
    return [[NSAttributedString alloc] initWithString:des attributes:attributes];
}

//- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state {
//
//    NSString *btnTitle;
//    switch (self.dznEmptyStatus) {
//        case DZNEmptyStatusNormal:
//            btnTitle = NSLocalizedString(@"暂无数据btn", nil);
//            break;
//        case DZNEmptyStatusFailure: {
//            btnTitle = NSLocalizedString(@"加载失败btn", nil);
//            break;
//        }
//        case DZNEmptyStatusNotOnLine: {
//            btnTitle = NSLocalizedString(@"重新加载btn", nil);
//            break;
//        }
//    }
//
//    if (!btnTitle)
//        return nil;
//
//    NSDictionary *attributes = @{NSFontAttributeName : kGeneralFontSize,
//            NSForegroundColorAttributeName : [UIColor colorWithHex:@"3c3c3c"]};
//    return [[NSAttributedString alloc] initWithString:btnTitle attributes:attributes];
//
//}

//- (UIImage *)buttonBackgroundImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state {
//
//    UIImage *btnBackImg = [[[UIImage imageNamed:@"qf_button_bak"] resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)
//                                                                                 resizingMode:UIImageResizingModeStretch]
//            imageWithAlignmentRectInsets:UIEdgeInsetsMake(10.f, -110.f / 350.f * kMainScreenWidth, 10.f, -110.f / 350.f * kMainScreenWidth)];
//    return btnBackImg;
//
//}

//- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView {
//    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
//    animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
//    animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)];
//    animation.duration = 0.25;
//    animation.cumulative = YES;
//    animation.repeatCount = MAXFLOAT;
//
//    return animation;
//}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return NO;
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView {
    return self.dznEmptyStatus == DZNEmptyStatusNotOnLine ||
        self.dznEmptyStatus == DZNEmptyStatusFailure;
}

//- (BOOL)emptyDataSetShouldAnimateImageView:(UIScrollView *)scrollView {
//    return self.dznEmptyStatus == DZNEmptyStatusLoading;
//}
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
//- (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button {


    self.reloadBlock ? self.reloadBlock() : nil;

}

#pragma mark -getter -setter

- (void)setDznEmptyStatus:(DZNEmptyStatus)dznEmptyStatus {

    _dznEmptyStatus = dznEmptyStatus;
    [_scrollView reloadEmptyDataSet];
}


@end
